﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace CompilerLib.Scanner.Generator
{
   public  class DFAModel
    {
        private NFAModel nfa;
        private List<char> charSet;
        public DFAModel(NFAModel nfa)
        {
            this.nfa = nfa;
        }
        //public DFAModel ConvertFrom(NFAModel nfa, List<char> charSet)
        //{
        //    NFAState start = nfa.EntryEdge.TargetState;
        //    var dfaStart = getEqState(start);
        //}
        public List<NFAState> getEqState(NFAState nfaS)
        {
            List<NFAState> nfaStates = new List<NFAState>();
            var eqStates = from edge in nfaS.OutEdges
                           where edge.Symbol == 'ε'
                           select edge.TargetState;
            nfaStates.Add(nfaS);
            nfaStates = nfaStates.Concat(eqStates).ToList();
            foreach (var s in eqStates)
            {
                nfaStates = nfaStates.Concat(getEqState(s)).ToList();
            }
            return nfaStates;
        }
        public List<NFAEdge> getEdges(List<NFAEdge> edges, char c)
        {
            var result = from edge in edges
                         where edge.Symbol == c
                         select edge;
            return result.ToList();
        }
        public List<NFAEdge> getOutEdges(List<NFAState> states)
        {
            var ret = states.SelectMany(state => state.OutEdges.ToList()).ToList();
            return ret;
        }
    }
}
